/**
 * Copyright &copy; 2012-2016 <a href="https://istep.lczyfz.com">Istep</a> All rights reserved.
 */
package com.lczyfz.istep.modules.race.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.lczyfz.istep.common.config.Global;
import com.lczyfz.istep.common.persistence.Page;
import com.lczyfz.istep.common.web.BaseController;
import com.lczyfz.istep.common.utils.StringUtils;
import com.lczyfz.istep.modules.race.entity.RaceTeamScore;
import com.lczyfz.istep.modules.race.service.RaceTeamScoreService;

/**
 * 团队历史分数Controller
 * @author cfq
 * @version 2017-06-29
 */
@Controller
@RequestMapping(value = "${adminPath}/race/raceTeamScore")
public class RaceTeamScoreController extends BaseController {

	@Autowired
	private RaceTeamScoreService raceTeamScoreService;

	@ModelAttribute
	public RaceTeamScore get(@RequestParam(required = false) String id) {
		RaceTeamScore entity = null;
		if (StringUtils.isNotBlank(id)) {
			entity = raceTeamScoreService.get(id);
		}
		if (entity == null) {
			entity = new RaceTeamScore();
		}
		return entity;
	}

	@RequiresPermissions("race:raceTeamScore:view")
	@RequestMapping(value = {"list", ""})
	public String list(RaceTeamScore raceTeamScore, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<RaceTeamScore> page = raceTeamScoreService.findPage(new Page<RaceTeamScore>(request, response), raceTeamScore);
		model.addAttribute("page", page);
		return "modules/race/raceTeamScoreList";
	}

	@RequiresPermissions("race:raceTeamScore:view")
	@RequestMapping(value = "form")
	public String form(RaceTeamScore raceTeamScore, Model model) {
		model.addAttribute("raceTeamScore", raceTeamScore);
		return "modules/race/raceTeamScoreForm";
	}

	@RequiresPermissions("race:raceTeamScore:edit")
	@RequestMapping(value = "save")
	public String save(RaceTeamScore raceTeamScore, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, raceTeamScore)) {
			return form(raceTeamScore, model);
		}
		raceTeamScoreService.save(raceTeamScore);
		addMessage(redirectAttributes, "保存团队历史分数成功");
		return "redirect:" + Global.getAdminPath() + "/race/raceTeamScore/?repage";
	}

	@RequiresPermissions("race:raceTeamScore:edit")
	@RequestMapping(value = "delete")
	public String delete(RaceTeamScore raceTeamScore, RedirectAttributes redirectAttributes) {
		raceTeamScoreService.delete(raceTeamScore);
		addMessage(redirectAttributes, "删除团队历史分数成功");
		return "redirect:" + Global.getAdminPath() + "/race/raceTeamScore/?repage";
	}

}